﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Diagnostics;


namespace Quan_Ly_Phong_Kham_co_len_em
{
    public class Clsdatabase
{
        private string pscon;
        //private string strSql;
        private string strerror = "";

        public SqlConnection mycon;
        public Clsdatabase(string strcon)
        {
              pscon = strcon;
        }

        public string connection {
        get { return pscon; }
        set { pscon = value; }
        }

        public string openconnection()
        {
              pscon = "Data Source=NGUYENTY-PC\\SQLEXPRESS;Initial Catalog=QL_PHONGKHAM;Integrated Security=True";
             
        try {
        mycon = new SqlConnection(pscon);
        mycon.Open();
        strerror = "OK";
        } catch (SqlException eq) {
        strerror = eq.Message;
        } catch (Exception ex) {
        strerror = ex.Message;
        }
            return strerror;
        }
        public void Closeconnection()
        {
        if (mycon.State != ConnectionState.Closed) {
        mycon.Close();
        mycon.Dispose();
        }
        }

        public string doSQL(string strSql)
        {
         string strError = "";
            pscon = "Data Source=NGUYENTY-PC\\SQLEXPRESS;Initial Catalog=QL_PHONGKHAM;Integrated Security=True";
        
        SqlConnection mycon = new SqlConnection(pscon);
        try {
        mycon.Open();
        SqlCommand mycom = new SqlCommand(strSql, mycon);
        mycom.ExecuteNonQuery();
        } catch (Exception ex) {
        strError = ex.Message;
        }
        return strError;
        }

        public string Getvalue(ref DataTable mydt, string strSql)
        {
         SqlDataAdapter adData = null;

        try {
             adData = new SqlDataAdapter(strSql, mycon);
               adData.Fill(mydt);
             strerror = "OK";
        } catch (Exception ex) {
            strerror = ex.Message;

        }
        return strerror;
        }
    }
    }
